package cn.biz.imp;

import java.util.List;

import cn.biz.UserBiz;
import cn.dao.UserDao;
import cn.entity.User;

public class UserBizImp implements UserBiz {
	private UserDao userDao;

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/*
	 * 插入一条
	 * 
	 * @see cn.biz.UserBiz#insert(cn.entity.User)
	 */
	@Override
	public String insert(User user) {
		String result = "error";
		try {
			userDao.insert(user);
			result = "success";
		} catch (Exception e) {
			result = "error";
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 登陆方法 找到对应账号密码
	 * 
	 * @see cn.biz.UserBiz#login(cn.entity.User)
	 */
	@Override
	public List login(User user) {
		return userDao.login(user);
	}

	/*
	 * 完善信息方法 更新成功返回true否则返回false
	 * 
	 * @see cn.biz.UserBiz#login(cn.entity.User)
	 */
	@Override
	public boolean update(User user) {
		boolean result = false;
		try {
			userDao.update(user);
			result = true;
		} catch (Exception e) {
			result = false;
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 获取所有用户列表
	 */
	@Override
	public List getAllUsers() {
		return userDao.getAllUsers();
	}

	/*
	 * 按照ID查询user
	 * 
	 * @see cn.biz.UserBiz#getUserById(java.lang.Integer)
	 */
	@Override
	public User getUserById(Integer id) {
		return userDao.getUserById(id);
	}

	@Override
	public boolean isExist(User user) {
		boolean flag = false;
		if(userDao.getUserByUsername(user.getUsername()).size()>0){
			flag = true;
		}
		return flag;
	}
	
	/*
	 * 返回用户类型
	 * 
	 * @see cn.biz.UserBiz#getType(java.lang.String)
	 */
	@Override
	public String getType(String type) {
		return userDao.getType(type);
	}
}
